Option Strict Off
Option Explicit On
Namespace BMLERP
	Friend Class frmPUR220
		Inherits System.Windows.Forms.Form
		Dim WithEvents rst As ADODB.Recordset
		Dim sql As String
		Private Sub Is_data_Item()
			Dim para1 As String
			Dim para2 As String
			Dim para3 As String
			Dim para4 As String

			para1 = Item.Text
			para2 = IIf(ChkDate.CheckState = 1, 1, 0)
			para3 = VB6.Format(Fdate.Text, "mm/dd/yyyy")
			para4 = VB6.Format(Tdate.Text, "mm/dd/yyyy")

			Adodc1.ConnectionString = ConnectString
			Adodc1.CommandTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "exec sp_PurIssueData '" & para1 & "','" & para2 & "','" & para3 & "','" & para4 & "'"
			'MsgBox "sp_PurIssueData '" & para1 & "','" & para2 & "','" & para3 & "','" & para4 & "'"
			Adodc1.Refresh()
			DataGrid.DataSource = Adodc1
		End Sub


		Private Sub BItem_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles BItem.Change
			On Error Resume Next
			Item.Text = BItem.BoundText
			If Item.Text <> "" Then
				Call Is_data_Item()
			End If
		End Sub

		Private Sub BItem_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles BItem.KeyPressEvent
			On Error Resume Next
			If Item.Text <> "" Then
				Call Is_data_Item()
			End If
		End Sub

		Private Sub Bpurno_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Bpurno.Change
			Dim cmd As New ADODB.Command
			Dim cmd1 As New ADODB.Command
			If Bpurno.CtlText = "" Then
				cmd.let_ActiveConnection(ConnectString)
				cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
				cmd.CommandText = "exec purno '" & Trim(Fno.CtlText) & "','" & Trim(Tno.CtlText) & "'"
				cmd.Execute()
				Adodc1.ConnectionString = ConnectString
				Adodc1.CommandTimeout = 10
				Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
				Adodc1.RecordSource = "select * from purno_"
				Adodc1.Refresh()
				DataGrid.DataSource = Adodc1
			Else
				cmd1.let_ActiveConnection(ConnectString)
				cmd1.CommandType = ADODB.CommandTypeEnum.adCmdText
				cmd1.CommandText = "exec PURnofinishItem '" & Trim(Bpurno.CtlText) & "'"
				cmd1.Execute()
				Adodc1.ConnectionString = ConnectString
				Adodc1.CommandTimeout = 10
				Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
				Adodc1.RecordSource = "select * from purno_"
				Adodc1.Refresh()
				DataGrid.DataSource = Adodc1
			End If
		End Sub

		Private Sub ChkDate_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ChkDate.CheckStateChanged
			If ChkDate.CheckState = 1 Then
				FraDate.Enabled = True
				Fdate.Enabled = True
				Tdate.Enabled = True
				Fdate.Text = "01/" & VB6.Format(Now, "mm") & "/" & VB6.Format(Now, "yyyy")
				Tdate.Text = VB6.Format(Now, "dd/mm/yyyy")
			Else
				FraDate.Enabled = False
				Fdate.Enabled = False
				Tdate.Enabled = False
			End If
			If Item.Text <> "" Then
				Call Is_data_Item()
			End If
		End Sub

		Private Sub cmdclose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdclose.Click
			Me.Close()
		End Sub

		Private Sub cmdPrint_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPrint.Click
			If PurItem.Checked = True Then
				CrystalReport2.ReportFileName = DDAN & "\ReportItem.rpt"
				CrystalReport2.RetrieveStoredProcParams()
				CrystalReport2.set_StoredProcParam(0, VB6.Format(Trim(Fdate.Text), "mm/dd/yyyy"))
				CrystalReport2.set_StoredProcParam(1, VB6.Format(Trim(Tdate.Text), "mm/dd/yyyy"))
				CrystalReport2.set_StoredProcParam(2, Trim(Item.Text))
				CrystalReport2.Destination = Crystal.DestinationConstants.crptToWindow
				CrystalReport2.Action = 1
			End If
			If PurNo.Checked = True Then
				CrystalReport2.ReportFileName = DDAN & "\ReportPurchaseOrder.rpt"
				CrystalReport2.RetrieveStoredProcParams()
				CrystalReport2.set_StoredProcParam(0, Trim(Fno.CtlText))
				CrystalReport2.set_StoredProcParam(1, Trim(Tno.CtlText))
				CrystalReport2.Destination = Crystal.DestinationConstants.crptToWindow
				CrystalReport2.Action = 1
			End If
			If PurNof.Checked = True Then
				CrystalReport2.ReportFileName = DDAN & "\ReportByPONofinish.rpt"
				CrystalReport2.RetrieveStoredProcParams()
				CrystalReport2.set_StoredProcParam(0, Trim(Bpurno.CtlText))
				CrystalReport2.Destination = Crystal.DestinationConstants.crptToWindow
				CrystalReport2.Action = 1
			End If
		End Sub



		Private Sub Fdate_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles Fdate.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				If IsDate(Fdate.Text) = True Then
					Tdate.Focus()
				Else
					'Debug.Print "err"
					MsgBox("Incorrect Date in the FromDate Textbox", MsgBoxStyle.Critical, "Warning...")
					GoTo EventExitSub
				End If
			End If
EventExitSub:
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


		Private Sub Fno_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles Fno.KeyPressEvent
			If eventArgs.keyAscii = 13 Then
				If IsNumeric(Fno.CtlText) = True Then
					Tno.Focus()
				Else
					MsgBox("You must enter numeric", MsgBoxStyle.Critical, "Warning")
					Exit Sub
				End If
			End If
		End Sub

		Private Sub frmPUR220_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

			FramI.Enabled = False
			FramNo.Enabled = False
			cmdPrint.Enabled = False
			PurItem.Checked = True
			PurNo.Checked = False
			PurNof.Checked = False


		End Sub

		Private Sub PurItem_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles PurItem.CheckedChanged
			If eventSender.Checked Then
				Dim sql As String
				sql = ""
				sql = sql & "SELECT distinct dbo.IIM.IMITN as Item,dbo.IIM.IMITN + ' : ' + dbo.IIM.IMITD AS thitn "
				sql = sql & "FROM dbo.POH INNER JOIN dbo.POL ON dbo.POH.OHPON=dbo.POL.OLPON INNER JOIN dbo.IIM ON dbo.POL.OLITN = dbo.IIM.IMITN "
				sql = sql & "where POL.OLSTT<>'5' OR POH.OHPOS<>'5' "
				' SQL = SQL & " order by dbo.IIM.IMITD"
				ADO1.ConnectionString = ConnectString
				ADO1.CommandTimeout = 10
				ADO1.CommandType = ADODB.CommandTypeEnum.adCmdText
				ADO1.RecordSource = sql
				ADO1.Refresh()
				BItem.RowSource = ADO1
				FramI.Enabled = True
				FramNo.Enabled = False
				'BItem.SetFocus
				BItem.CtlText = ""
				Fno.CtlText = ""
				Tno.CtlText = ""
				Bpurno.CtlText = ""
				DataGrid.DataSource = Nothing
				cmdprint.Enabled = True
				PurItem.Checked = True
				PurNo.Checked = False
				PurNof.Checked = False
			End If
		End Sub
		Private Sub PurNo_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles PurNo.CheckedChanged
			If eventSender.Checked Then
				PurItem.Checked = False
				PurNo.Checked = True
				PurNof.Checked = False
				DataGrid.DataSource = Nothing
				FramI.Enabled = False
				FramNo.Enabled = True
				Fno.Focus()
				BItem.CtlText = ""
				Fdate.Text = ""
				Tdate.Text = ""
				Fno.CtlText = ""
				Tno.CtlText = ""
				Bpurno.CtlText = ""
				cmdprint.Enabled = True
				Adodc2.ConnectionString = ConnectString
				Adodc2.ConnectionTimeout = 10
				Adodc2.CommandType = ADODB.CommandTypeEnum.adCmdText
				Adodc2.RecordSource = "Select OHPON from POH where isnumeric(OHPON)=1 ORDER BY OHPON DESC"
				Adodc2.Refresh()
				Fno.RowSource = Adodc2
				Tno.RowSource = Adodc2
			End If
		End Sub
		Private Sub PurNof_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles PurNof.CheckedChanged
			If eventSender.Checked Then
				PurItem.Checked = False
				PurNo.Checked = False
				PurNof.Checked = True
				sql = "SELECT  DISTINCT OLPON FROM POH INNER JOIN "
				sql = sql & "POL ON POH.OHPON = POL.OLPON "
				sql = sql & "WHERE     (POH.OHPOS = '1') OR  (POH.OHPOS = '2') OR  (POH.OHPOS = '3') OR (POH.OHPOS = '4')"
				ADO1.ConnectionString = ConnectString
				ADO1.CommandTimeout = 10
				ADO1.CommandType = ADODB.CommandTypeEnum.adCmdText
				ADO1.RecordSource = sql
				ADO1.Refresh()
				Bpurno.RowSource = ADO1
				DataGrid.DataSource = Nothing
				FramI.Enabled = False
				FramNo.Enabled = False
				BItem.CtlText = ""
				Fdate.Text = ""
				Tdate.Text = ""
				Fno.CtlText = ""
				Tno.CtlText = ""
				Bpurno.Focus()
				Dim cmd As New ADODB.Command
				cmd.let_ActiveConnection(ConnectString)
				cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
				cmd.CommandText = "exec PURnofinish"
				cmd.Execute()
				Adodc1.ConnectionString = ConnectString
				Adodc1.CommandTimeout = 10
				Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
				Adodc1.RecordSource = "select * from purno_"
				Adodc1.Refresh()
				DataGrid.DataSource = Adodc1
				cmdprint.Enabled = True
			End If
		End Sub
		Private Sub Tdate_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles Tdate.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then
				If IsDate(Tdate.Text) = True Then
					Call Is_data_Item()
				Else
					MsgBox("Incorrect Date in the ToDate Textbox", MsgBoxStyle.Critical, "Warning...")
					GoTo EventExitSub
				End If
			End If
EventExitSub:
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub


		Private Sub Tdate_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Tdate.Leave
			If PurItem.Enabled = True Then
				If IsDate(Tdate.Text) = True Then
					Call Is_data_Item()
				Else
					MsgBox("Incorrect Date in the ToDate Textbox", MsgBoxStyle.Critical, "Warning...")
					Exit Sub
				End If
			End If
		End Sub

		Private Sub TNo_KeyPressEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_KeyPressEvent) Handles TNo.KeyPressEvent
			Dim cmd As New ADODB.Command
			If eventArgs.keyAscii = 13 Then
				If IsNumeric(Tno.CtlText) = True Then
					cmd.let_ActiveConnection(ConnectString)
					cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
					cmd.CommandText = "exec purno '" & Trim(Fno.CtlText) & "','" & Trim(Tno.CtlText) & "'"
					cmd.Execute()
					Adodc1.ConnectionString = ConnectString
					Adodc1.CommandTimeout = 10
					Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
					Adodc1.RecordSource = "select * from purno_"
					Adodc1.Refresh()
					DataGrid.DataSource = Adodc1
				Else
					MsgBox("You must enter numeric in Textbox", MsgBoxStyle.Critical, "Warning...")
					Exit Sub
				End If
			End If
		End Sub
	End Class
End Namespace